/*****************************************************************
Mix3D WebGL Game Engine
Copyright (c) fantasy ( fantasy.x2x@gmail.com )
Listens:
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
 ****************************************************************/
/**
 * @Desc    : texture
 * @Author  : fantasy(fantasy.x2x@gmail.com)
 */
//////////////////////////////////////////////////////////////////
if(typeof(Mix3D) === 'undefined')
{
  Mix3D = {};
};
(function(Mix3D){
//////////////////////////////////////////////////////////////////
//
//              RenderTarget
//
//////////////////////////////////////////////////////////////////
Mix3D.RenderTarget = function(width, height, format, type)
{
  Mix3D.Resource.call(this);
  this.width = width;
  this.height = height;
  this.targetFormat = format !== undefined ? format : Mix3D.IMG_RGBA;;
  this.pixDataType = type !== undefined ? type : Mix3D.PDT_U8;
  this.wrapS = wrapS!==undefined?wrapS:Mix3D.WrappingMode_Clamp;
  this.wrapT = wrapT!==undefined?wrapT:Mix3D.WrappingMode_Clamp;
  this.magFilter = magFilter!==undefined?magFilter:Mix3D.Filter_Linear;
  this.minFilter = minFilter!==undefined?minFilter:Mix3D.Filter_LinearMipmapLinear;
  this.offset = new Mix3D.Vector2(0,0);
  this.repeat = new Mix3D.Vector2(1,1);
  this.isGenerateMipmaps = true;
  this.isDepth = false;
  this.enableDepthStencil = false;
};

Mix3D.RenderTarget.prototype.constructor = Mix3D.RenderTarget;
Mix3D.RenderTarget.prototype.className = 'RenderTarget';
Mix3D.RenderTarget.prototype.setWidth = function(width) { this.width = width; return this; };
Mix3D.RenderTarget.prototype.setHeight = function(height) { this.height = height; return this; };
Mix3D.RenderTarget.prototype.PixS8 = function(){ this.pixDataType = Mix3D.PDT_S8; return this;};
Mix3D.RenderTarget.prototype.PixU8 = function() { this.pixDataType = Mix3D.PDT_U8; return this; };
Mix3D.RenderTarget.prototype.PixS16 = function() { this.pixDataType = Mix3D.PDT_S16; return this; };
Mix3D.RenderTarget.prototype.PixU16 = function() { this.pixDataType = Mix3D.PDT_U16; return this; };
Mix3D.RenderTarget.prototype.PixS32 = function() { this.pixDataType = Mix3D.PDT_S32; return this; };
Mix3D.RenderTarget.prototype.PixU32 = function() { this.pixDataType = Mix3D.PDT_U32; return this; };
Mix3D.RenderTarget.prototype.PixF32 = function() { this.pixDataType = Mix3D.PDT_F32; return this; };
Mix3D.RenderTarget.prototype.UseAlpha = function() { this.targetFormat = Mix3D.IMG_Alpha; return this; };
Mix3D.RenderTarget.prototype.UseRGB = function() { this.targetFormat = Mix3D.IMG_RGB; return this; };
Mix3D.RenderTarget.prototype.UseRGBA = function() { this.targetFormat = Mix3D.IMG_RGBA; return this; };
Mix3D.RenderTarget.prototype.UseLU = function() { this.targetFormat = Mix3D.IMG_LU; return this; };
Mix3D.RenderTarget.prototype.UseLA = function() { this.targetFormat = Mix3D.IMG_LA; return this; };
Mix3D.RenderTarget.prototype.ClampS = function() { this.wrapS = Mix3D.WrappingMode_Clamp; return this; };
Mix3D.RenderTarget.prototype.RepeatS = function() { this.wrapS = Mix3D.WrappingMode_Repeat; return this; };
Mix3D.RenderTarget.prototype.MirrorS = function() { this.wrapS = Mix3D.WrappingMode_Mirror; return this; };
Mix3D.RenderTarget.prototype.ClampT = function() { this.wrapT = Mix3D.WrappingMode_Clamp; return this; };
Mix3D.RenderTarget.prototype.RepeatT = function() { this.wrapT = Mix3D.WrappingMode_Repeat; return this; };
Mix3D.RenderTarget.prototype.MirrorT = function() { this.wrapT = Mix3D.WrappingMode_Mirror; return this; };
Mix3D.RenderTarget.prototype.MagLinear = function() { this.magFilter = Mix3D.Filter_Linear; return this; };
Mix3D.RenderTarget.prototype.MagPoint = function() { this.magFilter = Mix3D.Filter_Point; return this; };
Mix3D.RenderTarget.prototype.MipmapPP = function() { this.minFilter = Mix3D.Filter_PointMipmapPoint; return this; };
Mix3D.RenderTarget.prototype.MipmapPL = function() { this.minFilter = Mix3D.Filter_PointMipmapLinear; return this; };
Mix3D.RenderTarget.prototype.MipmapLP = function() { this.minFilter = Mix3D.Filter_LinearMipmapPoint; return this; };
Mix3D.RenderTarget.prototype.MipmapLL = function() { this.minFilter = Mix3D.Filter_LinearMipmapLinear; return this; };
Mix3D.RenderTarget.prototype.setOffset = function( x, y ) { this.offset.set(x,y); return this; };
Mix3D.RenderTarget.prototype.setRepeat = function( u, v ) { this.repeat.set(u,v); return this; };
Mix3D.RenderTarget.prototype.setGenMipmaps = function(is) { this.isGenerateMipmaps = is; return this; };
Mix3D.RenderTarget.prototype.DepthTarget = function() { this.isDepth = true; return this; };
Mix3D.RenderTarget.prototype.enableDepthStencil = function(en) { this.enableDepthStencil = en; return this; };

Mix3D.RenderTarget.prototype.clone = function()
{
  var rt = new Mix3D.RenderTarget(this.width, this.height, this.targetFormat, this.pixDataType);
  rt.wrapS = this.wrapS;
  rt.wrapT = this.wrapT;
  rt.magFilter = this.magFilter;
  rt.minFilter = this.minFilter;
  rt.offset.copy(this.offset);
  rt.repeat.copy(this.repeat);
  rt.isGenerateMipmaps = this.isGenerateMipmaps;
  rt.isDepth = this.isDepth;
  rt.enableDepthStencil = this.enableDepthStencil;
  return rt;
};
//resource interface
Mix3D.RenderTarget.prototype.isReady = function()
{ 
  return this.__RT!==undefined; 
};

Mix3D.RenderTarget.prototype.create = function()
{
};

Mix3D.RenderTarget.prototype.release = function()
{
};

Mix3D.RenderTarget.prototype.load = function(stream) 
{
  this.width = stream.read('width');
  this.height = stream.read('height');
  this.targetFormat = stream.read('targetFormat');
  this.pixDataType = stream.read('pixDataType');
  this.wrapS = stream.read('wraps');
  this.wrapT = stream.read('wrapt');
  this.magFilter = stream.read('magFilter');
  this.minFilter = stream.read('minFilter');
  this.offset.fromArray(stream.read('offset'));
  this.repeat.fromArray(stream.read('repeat'));
  this.isGenerateMipmaps = stream.read('genMipmaps');
  this.isDepth = stream.read('isDepth');
  this.enableDepthStencil = stream.read('depthStencil');
};

Mix3D.RenderTarget.prototype.save = function(stream)
{
  stream.write('width', this.width);
  stream.write('height', this.height);
  stream.write('targetFormat', this.targetFormat);
  stream.write('pixDataType' this.pixDataType);
  stream.write('wraps', this.wrapS);
  stream.write('wrapt', this.wrapT);
  stream.write('magFilter', this.magFilter);
  stream.write('minFilter', this.minFilter);
  stream.write('offset', this.offset.toArray());
  stream.write('repeat', this.repeat.toArray());
  stream.write('genMipmaps', this.isGenerateMipmaps);
  stream.write('isDepth', this.isDepth);
  stream.write('depthStencil', this.enableDepthStencil);
};

Mix3D.protoCopy(Mix3D.Resource, Mix3D.RenderTarget);
Mix3D.defineResourceType(Mix3D.RenderTarget);
//////////////////////////////////////////////////////////////////
//
//              RenderTargetCube
//
//////////////////////////////////////////////////////////////////
Mix3D.RenderTargetCube = function( width, height, format, type)
{
  Mix3D.RenderTarget.call(this, width, height, format, type);
  this.isCube = true;
  this.activeCubeFace = 0; //PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
};

Mix3D.RenderTargetCube.prototype.constructor = Mix3D.RenderTargetCube;
Mix3D.RenderTargetCube.prototype.className = 'RenderTargetCube';

Mix3D.protoCopy(Mix3D.Resource, Mix3D.RenderTargetCube);
Mix3D.defineResourceType(Mix3D.RenderTargetCube);
//////////////////////////////////////////////////////////////////
})(Mix3D);// end of function(Mix3D)